/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlets;

import beans.SeekerCustomer;
import beans.SeekerUploadImg;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
 *
 * @author Dhruv
 */

//view all of this users images
public class ViewAllImagesAction extends Action {

    //constructor
    public ViewAllImagesAction(SeekerCustomer model) {
        super(model);
    }

    //identifies the operation name
    public String getName() {
        return "ViewAllImages";
    }

    public Object perform(HttpServletRequest req, HttpServletResponse resp) {

        //JSP page to dispatch the request to
        String address = "ViewAllImages.jsp";
        //use the session object to get the model object
        HttpSession session = req.getSession();
        model = (SeekerCustomer)session.getAttribute("session1");

        //retrieve this users image objects from database
        ArrayList<SeekerUploadImg> myImages = model.getMyImages();

        //store attribute(s) in this request, which is(are) reset between requests
        req.setAttribute("myImages", myImages);

        //below object receives requests from the client and sends them to JSP address
        RequestDispatcher dispatcher = req.getRequestDispatcher(address);
        try {
            dispatcher.forward(req, resp);
        } catch (ServletException ex) {
            Logger.getLogger(CreateUserAction.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
              Logger.getLogger(CreateUserAction.class.getName()).log(Level.SEVERE, null, ex);
        }

        //returning the object conforms to the Abstract Action class definition
        //object needed to maintain session between requests
        return model;
    }
}